package webone.context;

import java.util.HashMap;
import webone.javabean.OnlineUserInfo;

public class MyUserInfoContext {
	/**
	 * 
	 */
	private static MyUserInfoContext instance;
	private static HashMap<String, OnlineUserInfo> onlineUserInfoMap;
	private MyUserInfoContext() {
		onlineUserInfoMap = new HashMap<String, OnlineUserInfo>();
	}
	
	public HashMap<String, OnlineUserInfo> getOnlineUserInfoMap() {
		return onlineUserInfoMap;
	}

	public static MyUserInfoContext getInstance() {
		if (instance == null) {
			instance = new MyUserInfoContext();
		}
		return instance;
	}

	public synchronized void addUserInfoContext(OnlineUserInfo onlineUserInfo) {
		if (onlineUserInfo != null) {
			onlineUserInfoMap.put(onlineUserInfo.getSessionid(), onlineUserInfo);
		}
	}
	public synchronized void delUserInfoContext(String sessionID) {
		if (sessionID != null) {
			onlineUserInfoMap.remove(sessionID);
		}
	}

	public synchronized OnlineUserInfo getOnlineUserInfo(String sessionID) {
		if (sessionID == null) {
			return null;
		}
		return onlineUserInfoMap.get(sessionID);
	}


}
